﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.ruleinfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BLL.ruletype bll = new BLL.ruletype();
                DataSet ds = bll.GetAllList();
                ddltype.DataSource = ds.Tables[0];
                ddltype.DataTextField = "rtname";
                ddltype.DataValueField = "rtid";
                ddltype.DataBind();
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int rid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(rid);
                }
            }
        }

        private void ShowInfo(int rid)
        {
            lcs.BLL.ruleinfo bll = new lcs.BLL.ruleinfo();
            lcs.Model.ruleinfo model = bll.GetModel(rid);           
            this.ddltype.SelectedValue = model.rtid.ToString();
            this.txtrname.Text = model.rname;
            this.txtrnum.Text = model.rnum.ToString();
            this.txtwnum.Text = model.wnum.ToString();
            this.chkischecked.Checked = model.ischecked;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";            
            if (this.txtrname.Text.Trim().Length == 0)
            {
                strErr += "rname不能为空！\\n";
            }
            if (!PageValidate.IsNumberSign(txtrnum.Text))
            {
                strErr += "rnum格式错误！\\n";
            }
            if (!PageValidate.IsNumberSign(txtwnum.Text))
            {
                strErr += "wnum格式错误！\\n";
            }
            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                int rid = (Convert.ToInt32(Request.Params["id"]));
                int rtid = int.Parse(this.ddltype.SelectedValue);
                string rname = this.txtrname.Text;
                int rnum = int.Parse(this.txtrnum.Text);
                int wnum = int.Parse(this.txtwnum.Text);
                bool ischecked = this.chkischecked.Checked;
                lcs.Model.ruleinfo model = new lcs.Model.ruleinfo();
                model.rid = rid;
                model.rtid = rtid;
                model.rname = rname;
                model.rnum = rnum;
                model.wnum = wnum;
                model.ischecked = ischecked;
                lcs.BLL.ruleinfo bll = new lcs.BLL.ruleinfo();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
